package cn.shadow.jdbc;

import cn.shadow.model.User;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 冯啸迪
 */
public class JdbcDemo {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?characterEncoding=utf-8&serverTimezone=UTC","root","goodnight007");
        String sql = "select * from user where id = ?";

        PreparedStatement statement = con.prepareStatement(sql);
        statement.setString(1,"1");
        ResultSet resultSet = statement.executeQuery();
        List<User> users = new ArrayList<>();
        while (resultSet.next()){
            Integer id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            String password = resultSet.getString("password");
            User user = new User();
            user.setId(id);
            user.setName(name);
            user.setPassword(password);
            users.add(user);
        }
        System.out.println(users);

    }


}
